package cn.pconline.autoclub.service;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.GeliDao;
import org.gelivable.dao.GeliOrm;
import org.gelivable.dao.SqlBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.pconline.autoclub.entity.Club;
import cn.pconline.autoclub.entity.ClubIntegral;
import cn.pconline.autoclub.entity.ClubLimit;
import cn.pconline.autoclub.entity.ClubMember;
import cn.pconline.autoclub.entity.ClubPetrol;
import cn.pconline.autoclub.entity.ClubPetrolLog;
import cn.pconline.autoclub.entity.MemberPetrolDailyDetail;
import cn.pconline.autoclub.entity.MemberPetrolLog;
import cn.pconline.autoclub.entity.User;
import cn.pconline.autoclub.entity.UserLimit;
import cn.pconline.autoclub.util.DateUtils;
import cn.pconline.autoclub.util.Pager;

/**
 *
 * 油值调整,查询
 *
 * @author wanganning
 */
public class PetrolService {

    @Autowired
    private UserService userService;
    @Autowired
    private ClubService clubService;
    @Autowired
    private MemberService memberService;
    @Autowired
    private GeliDao geliDao;
    @Autowired
    private ClubLevelService levelService;
    @Autowired
    private ClubLevelService clubLevelService;
    @Autowired
    private PagerService pagerService;
    @Autowired
    private ClubLimitService clubLimitService;
    @Autowired
    GeliOrm geliOrm;
    @Autowired
    private UserLimitService limitService;
    @Autowired
    private StatService statService;
    //注意，以下积分配置是跟数据库的ID是对应好的！！！
    /** 推荐到首页 */
    public static final int ADD_PERSONAL_PETROL_ITEM_RECOMMEND = 1;
    /** 精华贴 */
    public static final int ADD_PERSONAL_PETROL_ITEM_PICK = 2;
    /** 新贴(主题、投票、提问) */
    public static final int ADD_PERSONAL_PETROL_ITEM_TOPIC = 3;
    /** 回帖 */
    public static final int ADD_PERSONAL_PETROL_ITEM_POST = 4;
    /** 手机端回帖 */
    public static final int ADD_PERSONAL_PETROL_ITEM_POST_WAP = 5;
    /** 连续签到1天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_1 = 6;
    /** 连续签到2天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_2 = 7;//连续签到2天
    /** 连续签到3天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_3 = 8;//连续签到3天
    /** 连续签到4天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_4 = 9;//连续签到4天
    /** 连续签到5天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_5 = 10;//连续签到5天
    /** 连续签到6天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_6 = 11;//连续签到6天
    /** 连续签到7天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_7 = 12;//连续签到7天
    /** 增加普通会员 */
    public static final int ADD_CLUB_PETROL_ITEM_MEMBER = 13;
    /** 设置认证车主 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP = 14;
    /**活动奖励 */
    public static final int ADD_CLUB_PETROL_ITEM_ACTIVITY = 15;
    /** 认证会员数达5人 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP_NUM_5 = 16;
    /** 认证会员数达10人 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP_NUM_10 = 17;
    /** 认证会员数达20人 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP_NUM_20 = 18;
    /** 认证会员数达30人 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP_NUM_30 = 19;
    /** 认证会员数达40人 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP_NUM_40 = 20;
    /** 认证会员数达50人 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP_NUM_50 = 21;
    /** 认证会员数达100人 */
    public static final int ADD_CLUB_PETROL_ITEM_VIP_NUM_100 = 22;
    /** 手机端签到1天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_WAP_1 = 23;
    /** 手机端签到2天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_WAP_2 = 24;
    /** 手机端签到3天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_WAP_3 = 25;
    /** 手机端签到4天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_WAP_4 = 26;
    /** 手机端签到5天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_WAP_5 = 27;
    /** 手机端签到6天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_WAP_6 = 28;
    /** 手机端签到7天 */
    public static final int ADD_PERSONAL_PETROL_ITEM_CHECKIN_WAP_7 = 29;
    /** 取消推荐到首页 */
    public static final int ADD_PERSONAL_PETROL_ITEM_RECOMMEND_CANCEL = 30;
    /** 删除贴(主题、投票、提问) */
    public static final int ADD_PERSONAL_PETROL_ITEM_TOPIC_DELETE = 31;
    /** 取消精华贴 */
    public static final int ADD_PERSONAL_PETROL_ITEM_PICK_CANCEL = 32;
    /** 删除回帖 */
    public static final int ADD_PERSONAL_PETROL_ITEM_POST_DELETE = 33;
    /** 删除手机端回帖 */
    public static final int ADD_PERSONAL_PETROL_ITEM_POST_WAP_DELETE = 34;
    /** 删除活动 */
    public static final int ADD_CLUB_PETROL_ITEM_ACTIVITY_DELETE = 35;
    /** 普通会员退出车友会 */
    public static final int ADD_CLUB_PETROL_ITEM_MEMBER_QUIT = 36;
    /** 取消认证车主 */ 
    public static final int ADD_CLUB_PETROL_ITEM_VIP_QUIT = 37;
    /** 手动修改油值 */
    public static final int ADD_CLUB_PETROL_ITEM_OPERATION = 38;
    private static final Logger log = LoggerFactory.getLogger(PetrolService.class);

    /**
     * 加分给个人
     *
     * @param member 车友会成员
     * @param item 加分项 请传入PetrolService.ADD_PERSONAL_PETROL
     * @param amount 加分值(不要在此方法内计算userlimit相关逻辑) 如果是减分传入负数
     * @param reason 加分原因
     * @param isLimit 是否通过积分限制给车友会加分
     * @return 成功:1,失败:0,异常:-1;
     */
    public int addToPerson(ClubMember member, long item, int amount, String reason, boolean isClubLimit) {
        //add to memberinfo
        int petrol = member.getPetrol() + amount;
        member.setPetrol(petrol < 0 ? 0 : petrol);
        int result = geliDao.update(member, "petrol");
        int time = DateUtils.formatData2YMD();
        Date now = DateUtils.getNow();
        //add to daily
        String sql = "SELECT * FROM ac_member_petrol_detail WHERE user_id=? AND club_id=? AND ymd=?";
        MemberPetrolDailyDetail detail = geliDao.findFirst(MemberPetrolDailyDetail.class,
                sql, member.getUid(), member.getClubId(), time);
        if (detail == null) {
            detail = new MemberPetrolDailyDetail();
            detail.setClubId(member.getClubId());
            detail.setPetrol(0);
            detail.setPickCancelCount(0);
            detail.setPickCount(0);
            detail.setPostCount(0);
            detail.setPostDeleteCount(0);
            detail.setRecommendCancelCount(0);
            detail.setRecommendCount(0);
            detail.setTopicCount(0);
            detail.setTopicDeleteCount(0);
            detail.setUid(member.getUid());
            detail.setCreateAt(now);
            detail.setUpdateAt(now);
            detail.setYmd(time);
            long id = geliDao.create(detail);
            detail.setId(id);
        }
        detail.setPetrol(detail.getPetrol() + amount);
        switch ((int) item) {
            case ADD_PERSONAL_PETROL_ITEM_TOPIC:
                detail.setTopicCount(detail.getTopicCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_TOPIC_DELETE:
                detail.setTopicDeleteCount(detail.getTopicDeleteCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_POST:
                detail.setPostCount(detail.getPostCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_POST_DELETE:
                detail.setPostDeleteCount(detail.getPostDeleteCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_PICK:
                detail.setPickCount(detail.getPickCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_PICK_CANCEL:
                detail.setPickCancelCount(detail.getPickCancelCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_RECOMMEND:
                detail.setRecommendCount(detail.getRecommendCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_RECOMMEND_CANCEL:
                detail.setRecommendCancelCount(detail.getRecommendCancelCount() + 1);
                break;
        }
        int result2 = geliDao.update(detail);

        //log
        if (result > 0 && result2 > 0) {
            MemberPetrolLog lo = new MemberPetrolLog();
            lo.setUid(member.getUid());
            lo.setClubId(member.getClubId());
            lo.setCreateAt(DateUtils.getNow());
            lo.setReason(reason);
            lo.setPetrol(amount);
            geliDao.create(lo);
        }
        //给车友会加分
        addToClubWithinLimit(member.getClubId(), item, amount, reason + "(uid_" + member.getUid() + ")", isClubLimit);

        return result;
    }

    /**
     * 通过是否有积分限制给用户、车友会加分
     *
     * @param member 车友会会员
     * @param item 加分类型
     * @param amount 加分分值
     * @param reason 加分原因
     * @param isLimit 是否有积分限制 注：给个人加分，必定给车友会加分
     * @return
     */
    public int addToPersonWithinLimit(ClubMember member, long item, int amount, String reason, boolean isMembLimit, boolean isClubLimit) {
        Club club = null;
        
        if (member == null || member.getUid() <= 0) {
            return 0;
        }
        
        if (amount < 0) {
            club = clubService.getClub(member.getClubId());
        } else {
            club = clubService.getNormalClub(member.getClubId());
        }
        
        if (club == null) {
            return 0;
        }
        int result = 0;
        int rankPetrol = amount;
        if (!isMembLimit || amount < 0) {
            //减分操作
            result = addToPerson(member, item, amount, reason, isClubLimit);
        } else if (isMembLimit) {
            UserLimit limit = limitService.getMemberLimit(member.getId());
            if (limit.getPetrol() < UserLimit.DAILY_PERSON_LIMIT) { // 未满限制
                result = addToPerson(member, item, amount, reason, isClubLimit);
                limitService.update(member.getId(), amount); // 更新今日油值限制
            } else {
                rankPetrol = 0;
                log.info("用户ID：" + member.getUid() + " 的用户今日油值已满限制"
                        + UserLimit.DAILY_PERSON_LIMIT + ", 不再加油!");
            }
        }
        // 周排行榜
        statService.updateWeekRank(member.getClubId(), member.getUid(), rankPetrol, item);
        //总排行榜
        statService.updateAllRank(member.getClubId(), member.getUid(), rankPetrol, item);
        return result;
    }

    /**
     * 通过限制积分给车友会加分
     *
     * @param clubId
     * @param item 加分类型
     * @param amount 加分分值
     * @param reason 加分原因
     * @param isLimit 是否有积分限制
     * @return
     */
    public void addToClubWithinLimit(long clubId, long item, int amount, String reason, boolean isLimit) {
        Club club;
        if (amount < 0) {
            club = clubService.getClub(clubId);
        } else {
            club = clubService.getNormalClub(clubId);
        }
        if (club == null) {
            return;
        }
        if (!isLimit || amount < 0) {
            //减分操作
            if (club.getTotalPetrol() + amount <= 0) {
                amount = (int) -club.getTotalPetrol();
            }
            addToClub(clubId, item, amount, reason);
        } else if (isLimit) {
            ClubLimit clubLimit = clubLimitService.getMemberLimit(clubId);
            if (clubLimit.getPetrol() < clubLimitService.getClubTotalAdd(clubId)) { // 未满限制
                addToClub(clubId, item, amount, reason);
                clubLimitService.update(clubId, amount); // 更新今日油值限制
            } else {
                log.info("车友会ID：" + clubId + " 的今日油值已满限制"
                        + clubLimitService.getClubTotalAdd(clubId) + ", 不再加油!");
            }
        }
    }

    /**
     * 加分给车友会
     *
     * @param clubId
     * @param item 加分项 请传入PetrolService.ADD_CLUB_PETROL_...
     * @param amount 加分值
     * @param reason 加分原因
     */
    public void addToClub(long clubId, long item, int amount, String reason) {
        //item 暂时用不到
        synchronized (this) {
            ClubPetrol clubPetrol = null;
            try {
                clubPetrol = geliDao.find(ClubPetrol.class, clubId);
                long totalPetrol = clubPetrol.getTotalPetrol() + amount;
                clubPetrol.setTotalPetrol(clubPetrol.getTotalPetrol() + amount);
                clubPetrol.setUpdateAt(DateUtils.getNow());
                geliDao.update(clubPetrol);

                //更新车友会总油值对象
                Club club = clubService.getClub(clubId);
                if (club != null) {
                    club.setTotalPetrol(totalPetrol);
                    geliDao.update(club, "total_petrol");
                }

            } catch (DataAccessException e) {

                log.error(" cant't found the club where clubId is :" + clubId + " , will go create");
            }
            if (clubPetrol == null) {
                clubPetrol = new ClubPetrol();
                clubPetrol.setClubId(clubId);
                clubPetrol.setTotalPetrol(clubPetrol.getTotalPetrol() + amount);
                clubPetrol.setUpdateAt(DateUtils.getNow());
                geliDao.create(clubPetrol);
            }
            //添加油值记录数据
            ClubPetrolLog l = new ClubPetrolLog();
            l.setClubId(clubId);
            l.setCreateAt(DateUtils.getNow());
            l.setPetrol(amount);
            l.setReason(reason);
            geliDao.create(l);


            Club club = geliDao.find(Club.class, clubId);
            //是否要升级
            if (levelService.isUpLevel(club) == 5) {
                //发送升级消息
                clubLevelService.sendClubUpLevel(club, club.getLevelId());
            }
            int isDown = levelService.isDownLevel(club);
            //是否要降级
            if (isDown < 4 && isDown > 0) {
                //发送降级消息
                clubService.downClubLevel(clubId, isDown);
            }
        }
    }

    /**
     *
     * 查询积分日志, 如果车友会名或用户名没有匹配到任何车友会跟用户,会视作没有限制该条件 (如果要视作查出无结果,需修改此方法)
     * (车友会名称有重复时有问题)
     *
     * @param clubName 车友会名
     * @param username 用户名
     * @param createAtStart 起始时间
     * @param createAtEnd 结束时间
     * @param reason 积分调整原因
     * @param pageNo 分页号
     * @param pageSize 每页显示
     * @return
     */
    @SuppressWarnings("unchecked")
    public Pager<MemberPetrolLog> queryLog(String clubName, long clubId, String username,
            Date createAtStart, Date createAtEnd, String reason, int pageNo, int pageSize) {
        SqlBuilder sql = new SqlBuilder();
        long time = -28800000;//("1970-01-01 00:00:00").getTimg()
        //long choosetime = time;
        if (createAtStart == null || time == createAtStart.getTime()) {
            time = DateUtils.getNow().getTime();
        } else {
            time = createAtStart.getTime();
        }
        sql.appendSql(" select a.id from ").appendSql(geliOrm.getTableName(MemberPetrolLog.class, time)).appendSql(" a, ");
        sql.appendSql(" ac_club b, ac_user c  where a.club_id = b.club_id and a.user_id = c.user_id ");
        if (StringUtils.isNotBlank(clubName)) {
            sql.appendSql(" and b.name = ").appendValue(clubName);
        }
        if (clubId > 0) {
            sql.appendSql(" and b.club_id = ").appendValue(clubId);
        }
        if (StringUtils.isNotBlank(username)) {
            sql.appendSql(" and c.username = ").appendValue(username);
        }
        if (StringUtils.isNotBlank(reason) && (!reason.equals("0"))) {
            sql.appendSql(" and a.reason like ").appendValue(reason + "%");
        }
        if (createAtStart != null) {
            sql.appendSql(" and a.create_at>=").appendValue(createAtStart);
        }
        if (createAtEnd != null) {
            sql.appendSql(" and a.create_at<=").appendValue(createAtEnd);
        }
        sql.appendSql(" order by a.create_at desc ");
        Pager<MemberPetrolLog> pager = pagerService.pager(MemberPetrolLog.class, time, sql, pageNo, pageSize);
        if (pager.getResultList() != null && (!pager.getResultList().isEmpty())) {
            pager.setResultList(userService.loadTransientUsers(pager.getResultList()));
            pager.setResultList(clubService.loadTransientClubs(pager.getResultList()));
        }
        return pager;
    }

    /**
     * 查询会员积分详细
     *
     * @param clubName 车友会名
     * @param username 用户名
     * @param pageNo 分页号
     * @param pageSize 每页显示
     * @return
     */
    public Pager<ClubMember> queryMemberDetail(String clubName, String username, int pageNo, int pageSize) {
        long clubId = 0l;
        long uid = 0l;
        if (StringUtils.isNotBlank(clubName)) {
            Club club = clubService.findByName(clubName);
            if (club != null) {
                clubId = club.getClubId();
            }
        }

        if (StringUtils.isNotBlank(username)) {
            User user = userService.findByName(username);
            if (user != null) {
                uid = user.getUid();
            }
        }
        return memberService.getClubMemberPage(clubId, uid, pageNo, pageSize);
    }

    public ClubPetrol getValidPetrol(long clubId) {
        try {
            return geliDao.find(ClubPetrol.class, clubId);
        } catch (DataAccessException e) {
            log.error("车友会ID不存在，无法查询油值!");
        }
        return null;
    }

    /**
     * 获取积分配置表
     *
     * @author fxr
     * @return
     */
    public List<ClubIntegral> getIntegrals() {
        SqlBuilder sql = new SqlBuilder();
        sql.appendSql("SELECT club_integral_id FROM ac_club_integral");
        return geliDao.list(ClubIntegral.class, sql.getSql());
    }
    
    /**
     * 获取部分积分配置表
     *
     * @author fxr
     * @return
     */
    public List<ClubIntegral> getIntegralsForUserLog() {
        SqlBuilder sql = new SqlBuilder();
        int[] clubIntegralIds = {13,14,15,16,17,18,19,20,21,22,35,36,37,38,39,40,41,42};
        sql.appendSql("SELECT club_integral_id FROM ac_club_integral where club_integral_id not in( ");
        int len = clubIntegralIds.length;
        for (int i = 0; i < len; i++) {
                sql.appendValue(clubIntegralIds[i]);
                if (i < len - 1) {
                    sql.appendSql(",");
                }
        }
        sql.appendSql(") ");
 
       return geliDao.list(ClubIntegral.class, sql.getSql(), sql.getValues());
    }

    /**
     * 通过ID获取积分配置项
     * 请传入PetrolService.ADD_PERSONAL_PETROL_...or_ADD_CLUB_PETROL_...
     *
     * @param id
     * @return
     */
    public ClubIntegral getById(long id) {
        if (id < 1) {
            return null;
        }
        try {
            return geliDao.find(ClubIntegral.class, id);
        } catch (DataAccessException e) {
            log.error(String.format("clubIntegralId(%s) not exist!", id));
            return null;
        }
    }

    /**
     * 添加或修改积分配置
     *
     * @author fxr
     * @param o
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public long createOrUpdate(ClubIntegral o) {
        return o.getIntegralId() == 0
                ? geliDao.create(o) : geliDao.update(o, "name, petrol");
    }

    /**
     * 根据车友会ID车友会油值记录，》》车友会id主键
     *
     * @param clubId
     */
    public void deletePetrolByClubId(long clubId) {
        if (clubId < 1) {
            return;
        }
        ClubPetrol petrol = geliDao.find(ClubPetrol.class, clubId);
        if (petrol != null) {
            geliDao.delete(petrol, clubId);
        }
    }
    
    public int addPetrolOnlyPerson(ClubMember member, long item, int amount, String reason) {
        //add to memberinfo
        int petrol = member.getPetrol() + amount;
        member.setPetrol(petrol < 0 ? 0 : petrol);
        int result = geliDao.update(member);
        int time = DateUtils.formatData2YMD();
        Date now = DateUtils.getNow();
        //add to daily
        String sql = "SELECT * FROM ac_member_petrol_detail WHERE user_id=? AND club_id=? AND ymd=?";
        MemberPetrolDailyDetail detail = geliDao.findFirst(MemberPetrolDailyDetail.class,
                sql, member.getUid(), member.getClubId(), time);
        if (detail == null) {
            detail = new MemberPetrolDailyDetail();
            detail.setClubId(member.getClubId());
            detail.setPetrol(0);
            detail.setPickCancelCount(0);
            detail.setPickCount(0);
            detail.setPostCount(0);
            detail.setPostDeleteCount(0);
            detail.setRecommendCancelCount(0);
            detail.setRecommendCount(0);
            detail.setTopicCount(0);
            detail.setTopicDeleteCount(0);
            detail.setUid(member.getUid());
            detail.setCreateAt(now);
            detail.setUpdateAt(now);
            detail.setYmd(time);
            long id = geliDao.create(detail);
            detail.setId(id);
        }
        detail.setPetrol(detail.getPetrol() + amount);
        switch ((int) item) {
            case ADD_PERSONAL_PETROL_ITEM_TOPIC:
                detail.setTopicCount(detail.getTopicCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_TOPIC_DELETE:
                detail.setTopicDeleteCount(detail.getTopicDeleteCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_POST:
                detail.setPostCount(detail.getPostCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_POST_DELETE:
                detail.setPostDeleteCount(detail.getPostDeleteCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_PICK:
                detail.setPickCount(detail.getPickCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_PICK_CANCEL:
                detail.setPickCancelCount(detail.getPickCancelCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_RECOMMEND:
                detail.setRecommendCount(detail.getRecommendCount() + 1);
                break;
            case ADD_PERSONAL_PETROL_ITEM_RECOMMEND_CANCEL:
                detail.setRecommendCancelCount(detail.getRecommendCancelCount() + 1);
                break;
        }
        int result2 = geliDao.update(detail);

        //log
        if (result > 0 && result2 > 0) {
            MemberPetrolLog lo = new MemberPetrolLog();
            lo.setUid(member.getUid());
            lo.setClubId(member.getClubId());
            lo.setCreateAt(DateUtils.getNow());
            lo.setReason(reason);
            lo.setPetrol(amount);
            geliDao.create(lo);
        }
        return result;
    }
    
    public int addOnlyPersonWithinLimit(ClubMember member, long item, int amount, String reason, boolean isMembLimit) {
        if (member == null || member.getUid() <= 0) {
            return 0;
        }
        int result = 0;
        int rankPetrol = amount;
        if (!isMembLimit || amount < 0) {
            //减分操作
            result = addPetrolOnlyPerson(member, item, amount, reason);
            limitService.update(member.getId(), amount); // 更新今日油值限制
        } else if (isMembLimit) {
            UserLimit limit = limitService.getMemberLimit(member.getId());
            if (limit.getPetrol() < UserLimit.DAILY_PERSON_LIMIT) { // 未满限制
                result = addPetrolOnlyPerson(member, item, amount, reason);
                limitService.update(member.getId(), amount); // 更新今日油值限制
            } else {
                rankPetrol = 0;
                log.info("用户ID：" + member.getUid() + " 的用户今日油值已满限制" + UserLimit.DAILY_PERSON_LIMIT + ", 不再加油!");
            }
        }
        
        // 周排行榜
        statService.updateWeekRank(member.getClubId(), member.getUid(), rankPetrol, item);
        //总排行榜
        statService.updateAllRank(member.getClubId(), member.getUid(), rankPetrol, item);
        return result;
    }
}
